package controller;

import java.awt.Cursor;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import vue.AireDePoint;

import model.DefaultModel;
import model.ModelListener;

public class behaviourAireDePoint implements MouseListener,
		MouseMotionListener, ModelListener, KeyListener {

	protected static final double MARGE_CLIC = 20;
	private AireDePoint aireDePoint;
	private DefaultModel model;
	private InterfaceStateAireDePoint etat;

	public behaviourAireDePoint(AireDePoint aireDePoint, DefaultModel model) {
		this.aireDePoint = aireDePoint;
		this.model = model;

		aireDePoint.addMouseListener(this);
		aireDePoint.addMouseMotionListener(this);
		aireDePoint.setFocusable(true);
		aireDePoint.addKeyListener(this);
		model.addModelListener(this);
		
		etat = StateAireDePoint.init(model, aireDePoint);

	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		etat = etat.mousePressed(arg0.getPoint(), arg0.getButton());
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		etat = etat.mouseReleased(arg0.getPoint());

	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		etat = etat.mouseDragged(arg0.getPoint());

	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		etat = etat.mouseMoved(arg0.getPoint());
//		if (model.isOverPoint(arg0.getPoint()))
//			aireDePoint.setCursor(Cursor
//					.getPredefinedCursor(Cursor.HAND_CURSOR));
//		else
//			aireDePoint.setCursor(Cursor
//					.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}

	@Override
	public void onePointChange() {
		aireDePoint.repaint();

	}

	@Override
	public void keyPressed(KeyEvent arg0) {
//		if (arg0.getKeyCode() == KeyEvent.VK_ESCAPE) {
//			this.model.finishCourbe();
//			System.out.println("Début d'une nouvelle courbe");
//		}
		etat = etat.keyPress(arg0.getKeyCode());
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
	}

	@Override
	public void keyTyped(KeyEvent arg0) {

	}

}
